package com.xiaozhichao.springboot.listener;

import com.xiaozhichao.springboot.component.Demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class ApplicationListenerExample implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    Demo demo;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        Demo demo1 = (Demo)event.getApplicationContext().getBean("demo");
        System.out.println("我是事件监听器。。。。");
        System.out.println(demo1.toString());
        System.out.println(demo.toString());
        demo1.dothing();
    }
}
